package leetcode100;

import exer.ListNode;

import java.util.HashSet;

/**
 * @author shkstart
 * @create 2022-12-30-23:11
 */
public class jianzhi023 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        HashSet<ListNode> hashSet = new HashSet<>();
        ListNode temp = headA;
        while(temp!=null){
            hashSet.add(temp);
            temp=temp.next;
        }
        temp = headB;
        while (temp!=null){
            if(hashSet.contains(temp)){
                return temp;
            }
            temp = temp.next;
        }
        return null;
    }
}
